﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using lcmyjobs.Model;
namespace lcmyjobs.BLL
{
	/// <summary>
	/// adverts
	/// </summary>
	public partial class adverts
	{
		private readonly lcmyjobs.DAL.adverts dal=new lcmyjobs.DAL.adverts();
		public adverts()
		{}
		#region  Method
        public DataSet GetAdvnid(int uid)
        {
            return dal.GetAdvnid(uid);
        }
        public DataSet GetAdvnid(int min, int max)
        {
            return dal.GetAdvnid(min, max);
        }
        public DataSet Getpic(int apid)
        {
            return dal.Getpic(apid);
        }
		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int aid)
		{
			return dal.Exists(aid);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(lcmyjobs.Model.adverts model)
		{
			return dal.Add(model);
		}

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Addpic(lcmyjobs.Model.adverts model)
        {
            return dal.Addpic(model);
        }

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.adverts model)
		{
			return dal.Update(model);
		}

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Updatepic(int aid,int apid)
        {
            return dal.Updatepic(aid, apid);
        }

        public int Updateadv(string aid, string strset)
        {
            return dal.Updateadv(aid, strset);
        }

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int aid)
		{
			
			return dal.Delete(aid);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string aidlist )
		{
			return dal.DeleteList(aidlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.adverts GetModel(int aid)
		{
			
			return dal.GetModel(aid);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public lcmyjobs.Model.adverts GetModelByCache(int aid)
		{
			
			string CacheKey = "advertsModel-" + aid;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(aid);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (lcmyjobs.Model.adverts)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<lcmyjobs.Model.adverts> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<lcmyjobs.Model.adverts> DataTableToList(DataTable dt)
		{
			List<lcmyjobs.Model.adverts> modelList = new List<lcmyjobs.Model.adverts>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				lcmyjobs.Model.adverts model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new lcmyjobs.Model.adverts();
					if(dt.Rows[n]["aid"]!=null && dt.Rows[n]["aid"].ToString()!="")
					{
						model.aid=int.Parse(dt.Rows[n]["aid"].ToString());
					}
					if(dt.Rows[n]["pics"]!=null && dt.Rows[n]["pics"].ToString()!="")
					{
					model.pics=dt.Rows[n]["pics"].ToString();
					}
					if(dt.Rows[n]["alink"]!=null && dt.Rows[n]["alink"].ToString()!="")
					{
					model.alink=dt.Rows[n]["alink"].ToString();
					}
					if(dt.Rows[n]["locationid"]!=null && dt.Rows[n]["locationid"].ToString()!="")
					{
						model.locationid=int.Parse(dt.Rows[n]["locationid"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

